// xc_lshop/savemoney/jtklm/common/index.js
var actbill = require('../../model/jtklm.js')
var app = getApp();

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    xcmodel: null,
    CustomBar: app.globalData.CustomBar,
  },
  xcloaddata: function (options, config) {

    this.setconfig(options, config)

  },
  clickAd(e) {
   
    var item = e.currentTarget.dataset.item
    switch (item.cid) {
      case "9": {
        if (item.actid) {
          this.getacturl(item.actid, true)
        }
        break;
      }
      case "1": {
        if (item.url) {
          this.navigateTo(item.url)
        }
        break;
      }

    }
  },
  setconfig(options, config) {

    if (config['jtklmapi']) {
      if (config['jtklmapi']['status'] == -1) {

        this.pageback()
      } else {
        this.setData({
          actid: options.actid
        })
        this.getmodel(options.actid)
      }
    }
    console.log("this.data.mtui")
    console.log(this.data.mtui)

  },
  navtoxcx() {
    var we_app_info = this.data.acturl['we_app_info']
    wx.navigateToMiniProgram({
      appId: we_app_info['app_id'],
      path: we_app_info['page_path'],
      fail(e) {
        console.log(e)
      }
    })
  },
  shareposter() {

    var xcposter = this.selectComponent("#xcposter");
    // var mtui = this.data.mtui;
    var data = this.data.xcmodel.data;

    // var poster = data.poster;
    var bgimg = "";
    if (data.postertype == 2 && data.poster) {
      bgimg = data.poster;
    } else {
      bgimg = ""
    }


    if (this.data.acturl.we_app_info && this.data.acturl.we_app_info.miniCode) {
      var qrimg = this.data.acturl.we_app_info.miniCode;
      var qr = ""
    } else if (this.data.acturl.h5) {
      var qrimg = ""
      var qr = this.data.acturl.h5
    }

    xcposter.init(this.data.actid, bgimg, qrimg, qr)

    // var bgimg = poster; //"http://md.cohooo.net/attachment/images/2/2021/10/PsmAyyuxmzA4YTwmS7XK4y7979XfI9.png"
    //"http://p0.meituan.net/poiqrcode/74062c815334f1f98f369fd8e6657d9a100811.jpg"

    // acturl.we_app_info && acturl.we_app_info.miniCode

  },
  getmodel(id) {
    var that = this;
    console.log("iiiiiiiiiiiiiiisssssssssssssss")
    // console.log(source)
    // console.log(type)

    actbill.getactmodel(id).then(function (res) {
    
      if (res['status'] == 1) {
        // var name = 'list[' + type + ']';
        that.setData({
          xcmodel: res['obj']
        })

        that.getacturl(res['obj'].actid)
      }

    })
  },
  getacturl(actid, isgo = false) {
    var that = this;
    actbill.getacturl(actid).then(function (res) {
     
      if (res['status'] == 1) {
        if (isgo) {
          if(res['data']['we_app_info']){
            var we_app_info = res['data']['we_app_info']
            wx.navigateToMiniProgram({
              appId: we_app_info['app_id'],
              path: we_app_info['page_path'],
              fail(e) {
                console.log(e)
              } 
            })
          }
          
        }else{
          that.setData({
            acturl: res['data']
          })
        }
       
      }

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})